package com.ruoyi.web.controller.market.sys;

import java.util.List;
import java.util.Map;

import com.ruoyi.web.wapper.SmsRecordWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SmsRecord;
import com.ruoyi.sys.service.ISmsRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信管理Controller
 * 
 * @author admin
 * @date 2022-07-27
 */
@Controller
@RequestMapping("/sys/record")
public class SmsRecordController extends BaseController
{
    private String prefix = "sys/record";

    @Autowired
    private ISmsRecordService smsRecordService;

    @RequiresPermissions("sys:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询短信管理列表
     */
    @RequiresPermissions("sys:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SmsRecord smsRecord)
    {
        startPage();
        List<Map<String, Object>> mapList = smsRecordService.selectSmsRecordListMap(smsRecord);
        mapList = new SmsRecordWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出短信管理列表
     */
    @RequiresPermissions("sys:record:export")
    @Log(title = "短信管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SmsRecord smsRecord)
    {
        List<SmsRecord> list = smsRecordService.selectSmsRecordList(smsRecord);
        ExcelUtil<SmsRecord> util = new ExcelUtil<SmsRecord>(SmsRecord.class);
        return util.exportExcel(list, "短信管理数据");
    }

    /**
     * 新增短信管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信管理
     */
    @RequiresPermissions("sys:record:add")
    @Log(title = "短信管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SmsRecord smsRecord)
    {
        return toAjax(smsRecordService.insertSmsRecord(smsRecord));
    }

    /**
     * 修改短信管理
     */
    @RequiresPermissions("sys:record:edit")
    @GetMapping("/edit/{sid}")
    public String edit(@PathVariable("sid") String sid, ModelMap mmap)
    {
        SmsRecord smsRecord = smsRecordService.selectSmsRecordBySid(sid);
        mmap.put("smsRecord", smsRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信管理
     */
    @RequiresPermissions("sys:record:edit")
    @Log(title = "短信管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SmsRecord smsRecord)
    {
        return toAjax(smsRecordService.updateSmsRecord(smsRecord));
    }

    /**
     * 删除短信管理
     */
    @RequiresPermissions("sys:record:remove")
    @Log(title = "短信管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(smsRecordService.deleteSmsRecordBySids(ids));
    }
}
